﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SocialLearning
{
    public static class UAC_FH
    {
        public static List<string> GetContents(string file)
        {
            List<string> _return = new List<string>();
            string content = System.IO.File.ReadAllText(file);
            return _return = content.Split('|').ToList();
        }

        public static bool SaveContent(List<string> content, string location, bool append,bool serialize)
        {
            bool _return = false;
            string value = "";
            
            foreach (string list in content)
            {
                List<string> split = list.Split(';').ToList();
                value = string.Format("{0}|",value);
                if (serialize)
                {
                    if (value == "|")
                    {
                        value = string.Format("|{0}", list[0]);
                    }
                    else
                    {
                        value = string.Format("{0}", list[0]);
                    }
                }
                else
                {
                    foreach (string item in split)
                    {
                        if (value == "|")
                        {
                            value = string.Format("|{0}", item);
                        }
                        else
                        {
                            value = string.Format("{0};{1}", value, item);
                        }
                    }
                }
            }
            if (append)
            {
                System.IO.File.AppendAllText(location, value);
            }
            else
            {
                System.IO.File.WriteAllText(location, value);
            }
            return _return;
        }
    }
}
